package com.bdxk.android.imdemo.http;

import android.text.TextUtils;


import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import okhttp3.Interceptor;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.logging.HttpLoggingInterceptor;
import okio.BufferedSink;
import retrofit2.Retrofit;

/**
 * Created by Administrator on 2016/1/26.
 */
public class ApiClient {
    private static Retrofit imAdapter;
    private static Retrofit imAdapter1;
    private static ApiService apiService;

    public static String API_URL = "https://mobile2.youzirong.com/";
    public static String API_SHARE = "http://mobile-ns2.youzirong.com/mobile/vocity/share";
//    public static String API_URL = "https://mobile.youzirong.com/";
//    public static String API_SHARE = "http://mobile-ns.youzirong.com/mobile/vocity/share";
    public static String REC = "/mobile/vocity/rec";//推荐人介绍
    public static String TICKETS_RULE = "/mobile/vocity/ruledescription";//加息券使用规则
    public static String RED_PACKET = "/mobile/vocity/package";//红包使用规则
    public static String MY_REPORT = "/mobile/vocity/broker";//我的报表，包括经纪人等级说明，收益

    private static OkHttpClient client;
    static HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();

    public static ApiService getApiAdapter() {
         if (imAdapter == null) {
            loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
            OkHttpClient.Builder builder = new OkHttpClient.Builder();
            builder.connectTimeout(15, TimeUnit.SECONDS);
            builder.readTimeout(15, TimeUnit.SECONDS);
            builder.addInterceptor(loggingInterceptor);
            builder.build();
            client = builder.build();
            imAdapter = new Retrofit.Builder()
                    .baseUrl(API_URL)
                    .addConverterFactory(GsonConverterFactory.create())
                    .client(client)
                    .build();
        }
        apiService = imAdapter.create(ApiService.class);
        return apiService;
    }


    public static OkHttpClient getClient() {
        return client;
    }



}
